using System.Collections.ObjectModel;
using System.Linq.Expressions;
using System.Reflection;
using NHibernate.Hql.Ast;
using NHibernate.Linq;
using NHibernate.Linq.Functions;
using NHibernate.Linq.Visitors;

namespace Crux.Core.NHibernate.Test;
public class ExtendedEqualsGenerator : BaseHqlGeneratorForMethod
{
    public ExtendedEqualsGenerator()
    {
        // the methods call are used only to get info about the signature, the actual parameter is just ignored
        SupportedMethods = new[] {
            ReflectionHelper.GetMethodDefinition<Object>(x => x.Equals(string.Empty)),
        };
    }

    public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
    {
        return treeBuilder.Equality(
                visitor.Visit(targetObject).AsExpression(),
                visitor.Visit(arguments[0]).AsExpression());
    }
}

public class ExtendedLinqtoHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
{
    public ExtendedLinqtoHqlGeneratorsRegistry()
    {
        this.Merge(new ExtendedEqualsGenerator());
    }
}